$(function () {
    filter();
    findRoleByNusername(localStorage.getItem("username"));
})

function filter() {
    let data=myAjax("/user/username","","get");
    if (data.code==401){
        window.open("login.html","_self");
    } else {
        console.log(localStorage.getItem("token"))
        let usernam=localStorage.getItem("username");
        $("#username").text(usernam);
    }
}

function findRoleByNusername(usernam) {
    let data=myAjaxGet("/user/findRoleByNusername",{userName:usernam},"get");
    data=data.data;
    for (let i=0; i<data.length ;i++){
        if (data[i]=='教师' || data[i]=='系统管理员'){
            let html='<li class="layui-nav-item"><a href="javascript:$(\'#middle-reght\').load(\'daily/dailyFindAll.html\')">查看日报</a></li>';
            $("#daily").html(html);
            break;
        }else {
            let html='<li class="layui-nav-item"><a href="javascript:$(\'#middle-reght\').load(\'daily/dailyAdd.html\')">新建日报</a></li>\n' +
                '<li class="layui-nav-item"><a href="javascript:$(\'#middle-reght\').load(\'daily/myDailyFind.html\')">查看我的日报</a></li>';
            $("#daily").html(html);
        }
    }
}


function Exit() {
        localStorage.removeItem("token");
        localStorage.removeItem("username");
        window.open("login.html", "_self");
}
